/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
 *
 */

import * as path from 'path';

/**
 * 工程中的常用变量
 *
 * @since 2021/12/29
 */
export class CommonConst {
  static readonly HARMONY_OS: string = 'HarmonyOS';

  static readonly BUILD_FILE_NAME: string = 'hvigorfile.ts';

  static readonly PACKAGE_JSON: string = 'package.json';

  static readonly OH_PACKAGE_JSON5: string = 'oh-package.json5';

  static readonly DEPENDENCYMAP: string = 'dependencyMap';

  static readonly COMPILE_COMMANDS_JSON: string = 'compile_commands.json';

  static readonly OH_MODULES: string = 'oh_modules';

  static readonly OHPM: string = '.ohpm';

  static readonly LOCK_JSON5: string = 'lock.json5';

  static readonly PKG_MODULES: string = 'pkg_modules';

  static readonly CACHE: string = 'cache';

  static readonly BUILD: string = 'build';

  static readonly REMOTE_HSP: string = 'remote_hsp';

  static readonly BUILD_PROFILE_FIELDS: string = 'buildProfileFields';

  static readonly BUILD_MODE: string = 'buildMode';

  static readonly BUILD_MODE_NAME: string = 'buildModeName';

  static readonly LOCAL_PROPERTIES: string = 'local.properties';

  static readonly PROFILE_JSON5: string = 'build-profile.json5';

  static readonly MODULE_JSON: string = 'module.json';

  static readonly ARK_MODULE_JSON: string = 'ark_module.json';

  static readonly APP_SCHEMA_JSON: string = 'app.json';

  static readonly CONFIGURATION_JSON: string = 'configuration.json';

  static readonly FORM_SCHEMA_JSON: string = 'forms.json';

  static readonly PAGE_SCHEMA_JSON: string = 'pages.json';

  static readonly START_WINDOW_SCHEMA_JSON: string = 'startWindow.json';

  static readonly SYSTEM_THEME_JSON: string = 'themeConfig.json';

  static readonly PKG_CONTEXT_INFO_JSON: string = 'pkgContextInfo.json';

  static readonly LOADER_JSON: string = 'loader.json';

  static readonly ROUTER_MAP_SCHEMA_JSON: string = 'routerMap.json';

  static readonly SHORTCUTS_SCHEMA_JSON: string = 'shortcuts.json';

  static readonly APP_STARTUP_SCHEMA_JSON: string = 'appStartup.json';

  static readonly HSP_STARTUP_SCHEMA_JSON: string = 'appStartupInner.json';

  static readonly HAR_STARTUP_SCHEMA_JSON: string = 'appStartupInner.json';

  static readonly SYS_CAP_SCHEMA_JSON: string = 'sysCapSchema.json';

  static readonly PAC_SCHEMA_JSON: string = 'pacSchema.json';

  static readonly MODULE_JSON5: string = 'module.json5';

  static readonly CONFIG_JSON: string = 'config.json';

  static readonly APP_CONFIG: string = 'app.json5';

  static readonly APP_SCOPE: string = 'AppScope';

  static readonly ETS_WEBPACK_FILE: string = 'webpack.config.js';

  static readonly ACE_RICH_WEBPACK_FILE: string = 'webpack.rich.config.js';

  static readonly ACE_LITE_WEBPACK_FILE: string = 'webpack.lite.config.js';

  static readonly DEBUGGABLE: string = 'debuggable';

  static readonly HOT_RELOAD: string = 'hotReload';

  static readonly DEBUG_LINE: string = 'debugLine';

  static readonly PREVIEW_MODE: string = 'previewMode';

  static readonly UNIT_TEST_MODE: string = 'unitTestMode';

  static readonly OHOS_TEST_COVERAGE_SCOPE: string = 'scope';

  static readonly OHOS_TEST_COVERAGE_ALIAS: string = 'coverage';

  static readonly OHOS_TEST_COVERAGE: string = 'ohos-test-coverage';

  static readonly RPCID_JSON: string = 'rpcid.json';

  static readonly RPCID_SC: string = 'rpcid.sc';

  static readonly PCID_SC: string = 'pcid.sc';

  static readonly SYSCAP_JSON: string = 'syscap.json';

  static readonly DEVICES_GENERAL: string = 'general';

  static readonly DEVICES_CUSTOM: string = 'custom';

  static readonly RES_CONFIG_FILE: string = 'resConfig.json';

  static readonly OPT_COMPRESSION_FILE: string = 'opt-compression.json';

  static readonly WARM_UP_SCRIPT: string = path.resolve(__dirname, '../tasks/worker/worker-process-script.js/warmUp');

  static readonly ADDED_SYSCAPS: string = 'addedSysCaps';

  static readonly REMOVED_SYSCAPS: string = 'removedSysCaps';

  static readonly SYSTEM_CAPABILITY: string = 'syscap';

  static readonly DEVICE_TYPE: string = 'deviceType';

  static readonly DEVICE_TYPES: string = 'deviceTypes';

  static readonly COMPILE_CONFIG: string = 'compileConfig';

  static readonly PATCH_CONFIG: string = 'patchConfig';

  static readonly FRAMEWORK_CONFIGURATION: string = 'configuration/framework-configuration.json5';

  static readonly SINGLE_FRAMEWORK: string = 'single';

  static readonly DOUBLE_FRAMEWORK: string = 'double';

  static readonly OPEN_HARMONY: string = 'OpenHarmony';

  static readonly BASE_PROFILE: string = 'base/profile';

  static readonly SRC_MAIN: string = 'src/main';

  static readonly SRC_MAIN_RESOURCES = 'src/main/resources';

  static readonly ASSEMBLE_APP: string = 'assembleApp';

  static readonly ASSEMBLE_HAP: string = 'assembleHap';

  static readonly DEFAULT_PACKAGE_NAME: string = 'com.example.myapplication';

  static readonly DEFAULT_MODULE_NAME: string = '.entry';

  static readonly DEFAULT_DESIGN_WIDTH: number = 454;

  static readonly OBFUSCATION_TXT: string = 'obfuscation.txt';

  static readonly DISTRO_FILTER: string = 'distroFilter';

  static readonly OHOS_SDK_COMPONENT_DEFINITION: string = 'oh-uni-package.json';

  static readonly HMS_SDK_COMPONENT_DEFINITION: string = 'uni-package.json';

  static readonly OBFUSCATION_FILES_HASH: string = 'OBFUSCATION_FILES_HASH';

  static readonly OBFUSCATION_ENABLE: string = 'OBFUSCATION_ENABLE';

  static readonly COMPILE_SDK_VERSION: string = 'compileSdkVersion';

  static readonly COMPATIBLE_SDK_VERSION: string = 'compatibleSdkVersion';

  static readonly TARGET_SDK_VERSION: string = 'targetSdkVersion';

  static readonly INSIGHT_INTENT_SCHEMA_JSON: string = 'insightIntent.json';

  static readonly UTD_SCHEMA_JSON: string = 'customUtds.json';

  static readonly ARK_DATA_SCHEMA_JSON: string = 'arkDataSchema.json';

  static readonly ENABLE_SIGN_TASK: string = 'enableSignTask';

  static readonly OHOS_PROCESSLIB_OPTIMIZATION: string = 'ohos.processLib.optimization';

  static readonly KEEP_DEPENDENCY: string = 'hvigor.keepDependency';

  static readonly SKIP_NATIVE_INCREMENTAL: string = 'skipNativeIncremental';

  static readonly UNIT_TEST: string = 'unitTest';

  static readonly OHOS_TEST: string = 'ohosTest';

  static readonly COVERAGE_PATH_FILTER: string = 'coverage-path-filter';

  static readonly COVERAGE_MODE: string = 'coverage-mode';

  static readonly MOCK_CONFIG_JSON5: string = 'mock-config.json5';

  static readonly BUILD_DIR_KEY = 'ohos.buildDir';

  static readonly HAR_VERSION: string = 'harVersion';

  static readonly IS_LOCAL_TEST: string = 'isLocalTest';

  static readonly IS_OHOS_TEST: string = 'isOhosTest';

  static readonly API_VERSION: string = 'api_version';

  static readonly NO_EXTERNAL_IMPORT_BY_PATH: string = 'noExternalImportByPath';

  static readonly PARAMETER_FILE: string = 'parameterFile';

  static readonly ETS: string = 'ets';

  static readonly RESOURCES_PATH: string = 'resources';

  static readonly PAGES: string = 'pages';

  static readonly ON_DEVICE_TEST: string = 'onDeviceTest';

  static readonly ICON: string = 'icon';

  static readonly LABEL: string = 'label';

  static readonly REMOTE_HSP_CACHE = 'remoteHspCache.json';

  static readonly BUILD_CACHE_DIR = 'build-cache-dir';

  static readonly REQUIRED_DEVICE_TYPE: string = 'requiredDeviceType';

  static readonly USE_NORMALIZED_OHM_URL: string = 'useNormalizedOHMUrl';

  static readonly ROUTER_MAP: string = 'routerMap';

  static readonly SHORTCUTS_FIELD_NAME: string = 'ohos.ability.shortcuts';

  static readonly APP_STARTUP: string = 'appStartup';

  static readonly CHANGED_FILE_LIST: 'changedFileList.json';

  static readonly BISHENG: string = 'BiSheng';

  static readonly ORIGINAL_COMPILER: string = 'Original';

  static readonly USE_TS_HAR: string = 'UseTsHar';

  static readonly GLOB_MATCH_ALL_FILES: string = './**/*';

  static readonly SUB_DIR_PREFIX: string = './';

  static readonly USE_NATIVE_RESOLVER = 'ohos.nativeResolver';

  static readonly NO_EMIT_JS = 'ohos.arkCompile.noEmitJs';

  static readonly USE_TSC_RESOLVE = 'ohos.arkCompile.useTscResolve';

  static readonly USE_COLLECT_DEBUG_SYMBOL = 'ohos.collect.debugSymbol';

  static readonly LOCAL_DEPENDENCY_PREFIX = 'file:';

  static readonly EMPTY_BUNDLENAME = 'ohos.arkCompile.emptyBundleName';

  static readonly HAR_EXCLUDE_HSP_DEPENDENCIES = 'ohos.har.excludeHspDependencies';

  static readonly TSC_MAX_FLOW_DEPTH = 'maxFlowDepth';

  static readonly HYPIUM_PACKAGE_NAME = '@ohos/hypium';

  static readonly SINGLE_FILE_EMIT = 'ohos.arkCompile.singleFileEmit';

  static readonly DEFAULT_ENTITY = 'entity.system.home';

  static readonly DEFAULT_ACTION = 'action.system.home';

  static readonly COPY_CODE_RESOURCE_ENABLE = 'copyCodeResourceEnable';

  static readonly COPY_CODE_RESOURCE_EXCLUDES = 'copyCodeResourceExcludes';

  static readonly OHOS_UI_TRANSFORM_OPTIMIZATION = 'ohos.uiTransform.Optimization';

  static readonly OHOS_ROLLUP_CACHE_USE_SOURCE_HASH = 'ohos.rollupCache.useSourceHash';
  static readonly OHOS_ROLLUP_CACHE_USE_PATH_PLACEHOLDER = 'ohos.rollupCache.usePathPlaceholder';

  static readonly PAC_JSON = 'pac.json5';
  static readonly PAC_ONLY_JSON = 'pac.json';
  static readonly ENFORCE_OHPM = 'enforce-ohpm';
}

/**
 * Node环境中的常量
 */
export class CommonNodeConst {
  static readonly NODE_EXE: string = 'node.exe';

  static readonly NODE: string = 'node';

  static readonly NODE_MODULES: string = 'node_modules';
}

/**
 * module默认包含的target
 */
export class DefaultTargetConst {
  static readonly DEFAULT_TARGET: string = 'default';
  static readonly OHOS_TEST_TARGET: string = 'ohosTest';
  static readonly ALL_TARGET: string = 'all';
  static readonly FALLBACK_TARGET: string = 'ohos.fallback.target';
}

export class BuildProfileSchemaFileConst {
  static readonly HAP_MODULE_BUILD_PROFILE_SCHEMA_PATH: string = path.resolve(__dirname, '../../res/schemas/ohos-module-build-profile-schema.json');
  static readonly HAR_MODULE_BUILD_PROFILE_SCHEMA_PATH: string = path.resolve(__dirname, '../../res/schemas/ohos-har-module-build-profile-schema.json');
  static readonly PROJECT_BUILD_PROFILE_SCHEMA_PATH: string = path.resolve(__dirname, '../../res/schemas/ohos-project-build-profile-schema.json');
  static readonly ARKUI_X_CONFIG_SCHEMA_PATH: string = path.resolve(__dirname, '../../res/schemas/arkui-x-config-schema.json');
  static readonly HVIGOR_CONFIG_SCHEMA_PATH: string = path.resolve(__dirname, '../../../hvigor/res/hvigor-config-schema.json');
}

export class ConfigSchemaFileConst {
  static readonly MODULE_SCHEMA_PATH = path.resolve(__dirname, '../../res/schemas/hvigorfile-configuration/module-schema.json');
  static readonly HAR_MODULE_SCHEMA_PATH = path.resolve(__dirname, '../../res/schemas/hvigorfile-configuration/har-module-schema.json');
  static readonly PROJECT_SCHEMA_PATH = path.resolve(__dirname, '../../res/schemas/hvigorfile-configuration/project-schema.json');
}

export class ArkPackConst {
  static readonly COMPILE_TOOL: string = 'rollup';
  static readonly MAX_ARK_COMPILE_NUM: number = 5;
}

export enum PageType {
  PAGE = 'page',
  CARD = 'card',
}

export enum BundleType {
  APP = 'app',
  ATOMIC_SERVICE = 'atomicService',
  SHARED = 'shared',
  APP_PLUGIN = 'appPlugin'
}

export class CustomTypesConst {
  static readonly CUSTOM_TYPES_SUFFIX = ['.d.ets', '.d.ts'];
  static readonly CUSTOM_TYPES_INDEX = ['index.d.ets', 'index.d.ts'];
}

export class UnitTestConst {
  static readonly TEST_BUILD_ROOT = '.test';
  static readonly TEST_ABILITY = 'TestAbility';
  static readonly TEST_DEFAULT_MODE = 'module';
  static readonly TEST_DEFAULT_REPLACE_PAGE = '../../../.test/testability/pages/Index';
  static readonly TEST_ABILITY_ETS_PATH = 'testability/TestAbility.ets';
  static readonly ENTRY_TEST_ABILITY_PATH = '../../.test/testability/TestAbility.ets';
}

export class ArktSTaskConst {
  static readonly LEGACY_UNIT_TEST_ARKTS = 'LegacyUnitTestArkTS';
  static readonly UNIT_TEST_ARKTS = 'UnitTestArkTS';
  static readonly LINT_ARKTS = 'LintArkTS';
}

export class NativeConst {
  static readonly SHARED_STL_LIBRARY = 'libc++_shared.so';
  static readonly PACKAGE_SUMMARY_FILE = 'summary.cmake';
  static readonly PACKAGE_NAME_REGEX = /(@[\w-*.~]+\/)/;
  static readonly INCLUDE_DIR = 'include';
  static readonly LIBRARY_FILE_REGEXP = '.*\\.so(.*[0-9])?$';
  static readonly LIBRARY_FILE_PATTERN = '**/*.so*(.*[0-9])';
  static readonly LIBRARY_ALL_FILE_PATTERN = '**/*';
}

export class ValidateRegExp {
  static RELATIVE_PATH_REG_EXP = /\.{1,2}\/.*$/;
  static DYNAMIC_IMPORT_FILE_SUFFIX_REG_EXP = /^(ets|ts)$/;
  static SO_DEPENDENCY_REG_EXP = /lib(.+)\.so/;
  static JS_FILE_SUFFIX_REG_EXP = /^(js)$/;
  static STARTUP_TASK_SRC_ENTRY_REG_EXP = /^.(ets|ts|js)$/;
  static PRELOAD_STARTUP_TASK_SRC_ENTRY_REG_EXP = /\.so$/;
  static PAGE_SOURCE_FILE_REG_EXP = /^src\/.*$/;
}

export class HvigorConfigConst {
  static readonly OHOS_PACK_COMPRESS_LEVEL = 'ohos.pack.compressLevel';
  static readonly OHOS_COMPILE_LIB_ENTRY = 'ohos.compile.lib.entryfile';
  static readonly OHOS_SIGN_HAR = 'ohos.sign.har';
  static readonly OHOS_BYTE_CODE_HAR_OPTIMIZE = 'ohos.byteCodeHar.integratedOptimization';
  static readonly OHOS_PACK_COMPRESS_LEVEL_MAP = new Map([
    ['fast', '1'],
    ['standard', '5'],
    ['ultimate', '9'],
  ]);
}

/**
 * ability类型常量
 */
export class AbilityConst {
  static readonly UI_ABILITY = 'abilities';
  static readonly EXTENSION_ABILITY = 'extensionAbilities';
}

/**
 * 本地依赖参数化功能使用到的常量
 */
export const ParameterizationConst = {
  PREFIX: '@param:',
  REGEX: /@param:(.*?)(\s|$)/,
} as const;

/**
 * 本地依赖简化配置功能使用到的常量
 */
export const ModuleConst = {
  PREFIX: '@module:',
  REGEX: /@module:(.*?)(\s|$)/,
} as const;

/**
 * arkTSVersion
 */
export const ArkTSVersionConst = {
  DEFAULT: "1.1",
  ARKTS1_0: "1.0",
  ARKTS1_1: "1.1",
  ARKTS1_2: "1.2",
};

export const LanguageConst = {
  DEFAULT: "1.1",
  ARKTS1_0: "1.0",
  ARKTS1_1: "1.1",
  ARKTS1_2: "1.2",
  ARKTS_HYBRID: "hybrid",
};

export const ArkTSModeConst = {
  DYNAMIC: "dynamic",
  STATIC: "static",
  HYBRID: "hybrid"
};
